/**
 * @create 2022-06-01
 * @desc form-context
 */

import { createContext, FC, useContext, useMemo } from 'react';

interface FormContextProps {
  collapse?: boolean;
}

const formContext = createContext<FormContextProps>({
  collapse: true,
});

export const FormContextProvider: FC<FormContextProps> = ({ collapse = true, children }) => {
  const value = useMemo(() => {
    return { collapse };
  }, [collapse]);

  return <formContext.Provider value={value}>{children}</formContext.Provider>;
};

export const useFormContext = () => useContext(formContext);
